package v1

import (
	"tools-api/src/jcj/controller/controller_book"
	"tools-api/src/jcj/controller/controller_jcj"
	"tools-api/src/jcj/controller/controller_statistics"
	"tools-api/src/jcj/controller/controller_user"

	"github.com/gin-gonic/gin"
)

// AuthJCJ 聚财记接口注册
func AuthJCJ(r *gin.Engine) {
	jcj := r.Group("/jcj")
	{
		jcj.Use(controller_jcj.VerifySignature) // 签名校验
		common := jcj.Group("/user")
		{
			common.POST("/login", controller_user.Login)
			common.POST("/register", controller_user.Register)
			common.POST("/t_refresh", controller_jcj.AccessTokenExchange)
		}
		jcj.Use(controller_jcj.VerifyAccess) // 后续接口必须登录
		user := jcj.Group("/user")
		{
			user.POST("/logout", controller_user.Logout)
			user.GET("/infos", controller_user.GetUserInfo)
			user.POST("/mfa/enable", controller_user.MfaEnable)
			user.POST("/mfa/reset", controller_user.MfaReset)
		}
		book := jcj.Group("/book")
		{
			b := book.Group("/b")
			{ // 账本
				b.GET("/list", controller_book.BookList)
				b.POST("/add", controller_book.BookAdd)
				b.POST("/current", controller_book.BookSetCurrent)
				b.DELETE("/:id", controller_book.BookDelete)
			}
			detail := book.Group("/detail")
			{ // 记账明细
				detail.GET("/list", controller_book.DetailList)
				detail.POST("/add", controller_book.DetailAdd)
				detail.DELETE("/:id", controller_book.DetailDelete)
			}
			types := book.Group("/types")
			{ // 类别
				types.GET("/list", controller_book.TypesGetList)
				types.POST("/add", controller_book.TypesAdd)
				types.POST("/sort", controller_book.TypesSort)
				types.DELETE("/:id", controller_book.TypesDelete)
			}
			accounts := book.Group("/accounts")
			{ // 收支账户
				accounts.GET("/list", controller_book.AccountsGetList)
				accounts.POST("/add", controller_book.AccountsAdd)
				accounts.POST("/sort", controller_book.AccountsSort)
				accounts.POST("/def_set", controller_book.AccountSetDefault)
				accounts.DELETE("/:id", controller_book.AccountsDelete)
			}
		}
		statistics := jcj.Group("/statistics")
		{ // 统计报表
			bill := statistics.Group("/bill")
			{
				bill.GET("", controller_statistics.GetBillList)                       // 账单
				bill.GET("/account", controller_statistics.GetBillAccountList)        // 账单（收支账户）
				bill.GET("/daily", controller_statistics.GetBillDailyList)            // 每日账单
				bill.GET("/detail_types", controller_statistics.GetBillDetailByTypes) // 类别排行榜明细
			}
		}
	}
}
